const Koa = require('koa');

const app = new Koa();

app.use(async ctx => {
  if (ctx.method === 'GET' && ctx.url === '/') {
    ctx.body = `
      <h1>Koa2 request post</h1>
      <form action='/' method="POST">
        <p>userName</p>
        <input name="userName" />
        <p>age</p>
        <input name="age" />
        <p>website</p>
        <input name="website" />
        <p><button type="submit">提交</button></p>
      </form>
    `
  } else if (ctx.method === 'POST' && ctx.url === '/') {
    ctx.body = 'POST请求';
  }
})

app.listen(3030, () => {
  console.log('启动');
})